#include <iostream>
using namespace std;
#include "process.h" 
#include <time.h>
#include <stdlib.h>


double gtotal = 1024.0;
double speed = 1.0;

//函数指针类型 解耦合
typedef void (*cellback_cb)(double ,double);

double SpeedFloat(double start,double range)
{
    int int_range = (int)range;
    return start + rand()%int_range + range - int_range;
}

//cb 就是回调函数
void Download(int total,cellback_cb cb)
{
    srand(time(NULL));

    double curr = 0.0;
    while(1)
    {
        if(curr > total)
        {
            curr = total;
            //FlushProcess(total,curr);
            cb(total,curr);
            break;
        }
        //FlushProcess(total,curr);
        cb(total,curr);
        curr += SpeedFloat(speed,23.3);
        usleep(111000);
    }

    printf("\n");

}

int main()
{
    //Process();
    Download(2022,FlushProcess);    //此时传过去 只需要传函数名即可 即为传函数指针

    return 0;
}
